package org.baoping.gateway.filter;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.baoping.commom.api.CommonResult;
import org.baoping.demo.service.DemoService;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author HeZeMin
 * @className AuthorizationFilter
 * @description
 * @date 2021/1/15 11:44
 */
@Slf4j
@Component
public class AuthorizationFilter implements GlobalFilter {
    @Reference
    private DemoService demoService;

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("=====================**********进入 gateway ***************");
        CommonResult<String> commonResult = demoService.test("这是个参数");
        if (ObjectUtil.isNotNull(commonResult)) {
            log.info("dubbo调用结果：" + commonResult.getData());
        }
        return chain.filter(exchange);
    }
}